﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using DCRF.Common.Interface;
using DCRF.Common.Connection;

namespace DCRF.BaseBlocks.Commander.Console.Nodes
{
    public class BlockWebNode: INode
    {
        private TreeNode myNode = null;
        private IBlockWeb myWeb = null;

        public BlockWebNode(TreeNode node, IBlockWeb web)
        {
            myNode = node;
            myWeb = web;
            myNode.Tag = this;

            Refresh();
        }

        public List<string> Commands
        {
            get
            {
                List<string> result = new List<string>();
                result.Add("REF");

                return result;
            }
        }

        public object ProcessRequest(string serviceName, params object[] args)
        {
            if (serviceName == "REF")
            {
                Refresh();
            }
            else if (serviceName == "ADD")
            {
                int counter = (int)args[0];
                Connector c = args[1] as Connector;

                c.Raise("Item" + counter.ToString(), myWeb);
            }

            return null;
        }

        public void Refresh()
        {
            myNode.Nodes.Clear();

            myNode.Text = myWeb.Id;

            TreeNode blocks = new TreeNode();
            myNode.Nodes.Add(blocks);
            new BlocksNode(blocks, myWeb);

            TreeNode gc = new TreeNode();
            myNode.Nodes.Add(gc);

            new GlobalConnectorsNode(gc, myWeb);
        }
    }
}
